#include "UserInterface.h"
#include "UIInstruction.h"
#include "UserInterfaceException.h"

using namespace std;

std::shared_ptr<MyLogger> UserInterface::logger;
std::shared_ptr<PersistStorage> UserInterface::config;
std::unique_ptr<InstructionSrc> UserInterface::instSrc(nullptr);

void UserInterface::SetInstSrc(std::unique_ptr<InstructionSrc> &instSrc)
{
    UserInterface::instSrc.reset(instSrc.release());
}

void UserInterface::GetInstAndExecute()
{
    shared_ptr<InstInput> instIn = this->instSrc->GetInstruction();
    if (UIInstruction::instructionMap.find(instIn->instName) == UIInstruction::instructionMap.end()) {
        throw UnfoundInstruction("Instruction not found\n");
    }
    UIInstruction::instructionMap.at(instIn->instName)->Execute(instIn->args);
}

void UserInterface::SetLogger(std::shared_ptr<MyLogger> &logger)
{
    UserInterface::logger = logger;
}

void UserInterface::SetConfig(std::shared_ptr<PersistStorage> &config)
{
    UserInterface::config = config;
}
